package com.wly.ui.gamescene
{
	import com.wly.event.EventCodes;
	import com.wly.event.EventManager;
	import com.wly.ui.common.GlobalInfo;
	import com.wly.ui.panel.ResultPanel;
	import com.wly.ui.scene.SceneDefine;
	
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import Box2D.Common.Math.b2Vec2;
	
	public class GameStatLayer extends Sprite
	{
		private var _mcGameScene:GameScene;
		
		private var _btnBack:SimpleButton;
		private var _btnStart:SimpleButton;
		
		public function GameStatLayer()
		{
			super();
			_btnBack     = getChildByName("btnBack") as SimpleButton;
			if(_btnBack)
			{
				_btnBack.addEventListener(MouseEvent.CLICK, goBack);
				_btnBack.x = 10;
				_btnBack.y = 10;
			}
			
			_btnStart   = getChildByName("btnStart") as SimpleButton;
			if(_btnStart)
			{
				_btnStart.addEventListener(MouseEvent.CLICK, onStart);
			}
		}
		
		public function set gameScene(val:GameScene):void
		{
			_mcGameScene = val;
		}
		
		private function goBack(e:MouseEvent):void
		{
			EventManager.getInstance().dispatchEvent(EventCodes.EVENT_SCENE_UPDATE, SceneDefine.SCENE_WELCOME);
		}
		
		public function onStart(e:MouseEvent):void
		{
			if(_mcGameScene)
			{
				_mcGameScene.onStart();
			}
		}
		
		public function updateWinInfo(score:int):void
		{
			var result:ResultPanel = new ResultPanel();
			result.x = (GlobalInfo.fullWidth-result.width)/2;
			result.y = (GlobalInfo.fullHeight-result.height)/2;
			addChild(result);
			result.setCurScore(score);
		}
	}
}